import request from "@/utils/request"
import {AxiosPromise} from "axios";
import {RecordForm, RecordQuery, DeleteDTO, Recommend, TagVO, Top} from "./types";
import {Result, TableDataInfo} from "@/model";

/**
 * 查看记录列表
 * @param params 查询条件
 * @returns 记录列表
 */
export function getRecordList(params: RecordQuery): AxiosPromise<TableDataInfo> {
    return request({
        url: "/admin/record/list",
        method: "get",
        params,
    });
}

/**
 * 获取所有标签选项
 * @returns 标签选项
 */
export function getTagOption(): AxiosPromise<Result<TagVO[]>> {
    return request({
        url: "/admin/tag/option",
        method: "get"
    });
}

/**
 * 获取记录标签选项
 * @returns 标签选项
 */
export function getQTagOption(): AxiosPromise<Result<TagVO[]>> {
    return request({
        url: "/admin/rtag/option",
        method: "get"
    });
}

/**
* 添加记录
* @param data 记录信息
*/
export function addRecord(data: RecordForm): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/record/add",
        method: "post",
        data,
    });
}

/**
 * 物理删除记录
 * @param data 记录id
 */
export function deleteRecord(data: number[]): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/record/delete",
        method: "delete",
        data,
    });
}

/**
 * 逻辑删除记录
 * @param data 逻辑删除
 */
export function recycleRecord(data: DeleteDTO): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/record/recycle",
        method: "put",
        data,
    });
}

/**
 * 修改记录
 * @param data 记录信息
 */
export function updateRecord(data: RecordForm): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/record/update",
        method: "put",
        data,
    });
}

/**
 * 编辑记录
 * @param recordId 记录id
 */
export function editRecord(recordId: number): AxiosPromise<Result<RecordForm>> {
    return request({
        url: `/admin/record/edit/${recordId}`,
        method: "get",
    });
}

/**
 * 修改记录置顶状态
 * @param data 置顶信息
 */
export function updateRecordTop(data: Top): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/record/top",
        method: "put",
        data,
    });
}

/**
 * 修改记录推荐状态
 * @param data 推荐信息
 */
export function updateRecordRecommend(data: Recommend): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/record/recommend",
        method: "put",
        data,
    });
}

/**
 * 上传记录图片
 * @returns 图片链接
 */
export function uploadRecordImages(data: FormData): AxiosPromise<Result<string>> {
    return request({
        url: "/admin/recordImage/upload",
        headers: { "content-type": "multipart/form-data" },
        method: "post",
        data,
    });
}

/**
 * 上传记录视频
 * @returns 视频链接
 */
export function uploadRecordVideo(data: FormData): AxiosPromise<Result<string>> {
    return request({
        url: "/admin/recordVideo/upload",
        headers: { "content-type": "multipart/form-data" },
        method: "post",
        data,
    });
}